package com.incito.crawl.common.httpclient;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;

/**
 * Created by wuyu on 2014/7/11.
 */
public class CrawlHttpClientBuilder {
    private HttpClientBuilder httpClientBuilder;

    private HttpClientBuilder redirectDisabledHttpClientBuilder;

    public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder) {
        this.httpClientBuilder = httpClientBuilder;
    }

    public void setRedirectDisabledHttpClientBuilder(HttpClientBuilder redirectDisabledHttpClientBuilder) {
        this.redirectDisabledHttpClientBuilder = redirectDisabledHttpClientBuilder;
    }

    public CloseableHttpClient build(boolean redirectEnabled) {
        CloseableHttpClient httpClient = null;
        if (redirectEnabled) {
            httpClient = this.httpClientBuilder.build();
        }
        else {
            httpClient = this.redirectDisabledHttpClientBuilder.build();
        }
        return httpClient;
    }
}
